﻿using CTTest.Common;
using CTTest.Essential.Soap.OMS;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CTTest.Essential
{
    class OssUtil
    {
        public static bool TestContentMNGRequest(string COPID, string SOPID, string CorrelateID, string ContentMNGURL, WriteLogger log)
        {
            dynamic result;
            return TestContentMNGRequest(COPID, SOPID, CorrelateID, ContentMNGURL, log, out result);
        }

        public static bool TestContentMNGRequest(string COPID, string SOPID, string CorrelateID, string ContentMNGURL, WriteLogger log, out dynamic result)
        {
            Assert.IsNotNull(COPID, "COPID");
            Assert.IsNotNull(SOPID, "SOPID");
            Assert.IsNotNull(CorrelateID, "CorrelateID");
            Assert.IsNotNull(ContentMNGURL, "ContentMNGURL");
            Assert.IsNotNull(log, "WriteLogger log");

            using (contentMNG sc = new contentMNG())
            {
                log("Begin to invoke soap method {0}\r\n{1}", sc.Url,
                    TestUtil.WrapperObject(new
                    {
                        COPID = COPID,
                        SOPID = SOPID,
                        CorrelateID = CorrelateID,
                        ContentMNGURL = ContentMNGURL
                    }));

                var e = sc.ContentMNGRequest(COPID, SOPID, CorrelateID, ContentMNGURL);
                result = e;

                log("Finish to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(e));
                return e.resultCode == 0;
            }
        }
    }
}
